package com.base.framework.config;

import com.base.framework.domain.BaseModel;
import com.base.framework.web.action.BaseController;
import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.ext.plugin.tablebind.AutoTableBindPlugin;
import com.jfinal.ext.route.AutoBindRoutes;
import com.jfinal.plugin.druid.DruidPlugin;

public class ProjectConfig extends JFinalConfig {
	/**
	 * 配置常量
	 */
	@Override
	public void configConstant(Constants me) {
		loadPropertyFile("config/projectConfig.properties");
		me.setDevMode(getPropertyToBoolean("devMode"));
		me.setEncoding(getProperty("encoding"));
		me.setError404View(getProperty("404View"));

	}

	/**
	 * 配置路由
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void configRoute(Routes me) {
		AutoBindRoutes abr = new AutoBindRoutes();
		// 排除BaseController基类
		abr.addExcludeClasses(BaseController.class);
		abr.autoScan(true);
		me.add(abr);
	}

	@Override
	@SuppressWarnings("unchecked")
	public void configPlugin(Plugins me) {
		try {
			// 配置数据源
			IDataSource<DruidPlugin> dsc = (IDataSource<DruidPlugin>) Class
					.forName(getProperty("dsConfigClass")).newInstance();
			DruidPlugin dp = dsc.getDsConfig();

			me.add(dp);
			// ActiveRecordPlugin arp=new ActiveRecordPlugin(dp);
			// arp.setShowSql(getPropertyToBoolean("showSql"));
			// me.add(arp);
			// 配置自动扫描映射Model
			AutoTableBindPlugin atbp = new AutoTableBindPlugin(dp);
			atbp.setShowSql(getPropertyToBoolean("showSql"));
			atbp.addExcludeClasses(BaseModel.class);
			atbp.autoScan(true);
			me.add(atbp);
		 
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void configInterceptor(Interceptors me) {

	}

	@Override
	public void configHandler(Handlers me) {

	}
 

}
